﻿using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Editors;
using DevExpress.ExpressApp.Utils;
using HarmonyLib;

namespace EasyXaf.TreeListEditors.Blazor;

public class TreeListEditorsBlazorModule : ModuleBase
{
    public TreeListEditorsBlazorModule()
    {
        RequiredModuleTypes.Add(typeof(TreeListEditorsModule));

        DataAccessModeHelper.RegisterEditorSupportedModes(typeof(TreeListEditor), new List<CollectionSourceDataAccessMode> { CollectionSourceDataAccessMode.Client });
    }

    protected override void RegisterEditorDescriptors(EditorDescriptorsFactory editorDescriptorsFactory)
    {
        base.RegisterEditorDescriptors(editorDescriptorsFactory);

        editorDescriptorsFactory.RegisterListEditorAlias("TreeListEditor", typeof(ITreeObject<>), false);
        editorDescriptorsFactory.RegisterListEditor("TreeListEditor", typeof(ITreeObject<>), typeof(TreeListEditor), isDefaultEditor: false);
    }

    public void Patch()
    {
        var harmony = new Harmony(typeof(TreeListEditorsBlazorModule).FullName);
        harmony.PatchAll(typeof(TreeListEditorsBlazorModule).Assembly);
    }
}
